package com.un.web.topic.service.impl;

import cn.hutool.db.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.un.core.utils.ConvertUtil;
import com.un.web.topic.domian.entity.TopicJava;
import com.un.web.topic.domian.vo.TopicAuditVO;
import com.un.web.topic.domian.vo.TopicComVO;
import com.un.web.topic.mapper.TopicJavaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.un.web.topic.mapper.TopicAuditMapper;
import com.un.web.topic.domian.entity.TopicAudit;
import com.un.web.topic.service.TopicAuditService;

/**
 * @Author xingjian
 * @Date 2023-02-15
 **/

@Service
public class TopicAuditServiceImpl extends ServiceImpl<TopicAuditMapper, TopicAudit> implements TopicAuditService {

    @Autowired
    private TopicAuditMapper topicAuditMapper;

    @Autowired
    private TopicJavaMapper topicJavaMapper;
    @Override
    public PageInfo<TopicAudit> selectAllByPage(Page page) {
        PageHelper.startPage(page.getPageNumber(),page.getPageSize());
        List<TopicAuditVO> topicAuditVOS = topicAuditMapper.selectAllList();
        return new PageInfo<>(topicAuditVOS);
    }

    @Override
    public List<TopicComVO> getLikeTopicList(String keyword, String type) {
        List<TopicComVO> topicVO=null;
        switch (type){
            case "java":
                List<TopicJava> title = topicJavaMapper.selectList(new QueryWrapper<TopicJava>().like("title", keyword).eq("check_status",1));
                topicVO = ConvertUtil.entityToVoList(title, TopicComVO.class);
                break;
            case "python":
                break;
        }
        return topicVO;
    }
}

